﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace iLangl.Customer.DAL.XMLStorage
{
	public class AlertDAL : BaseStorageDAL, IAlertDAL
	{
		#region IAlertDAL Members

		public void SaveAlert(ISerializedAlert alert, IDbTransaction transaction)
		{
			dtoXmlStorage.AlertRow alertRow = Storage.Alert.FindById(alert.Id);

			bool isNew = (alertRow == null);

			if (isNew)
			{
				alertRow = Storage.Alert.NewAlertRow();
			}

			alertRow.Id = alert.Id;
			alertRow.DateCreated = alert.Created;
			alertRow.Content = alert.Content;
			alertRow.SiteId = alert.Source;
			alertRow.Severity = (int)alert.Severity;

			if (isNew)
			{
				Storage.Alert.AddAlertRow(alertRow);
			}

			

			if (transaction == null)
			{
				AcceptChanges();
			}
		}

		#endregion

		#region IAlertDAL Members

		public IList<ISerializedAlert> GetAlerts(TimeSpan from, TimeSpan to)
		{
			Facade.Instance.AlertManager.RaiseAlert(new NotImplementedException());
			return null;
		}

		#endregion
	}
}
